//
//  HNDownLoadFile.m
//  XDEducation
//
//  Created by 星道 on 17/6/5.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "HNDownLoadFile.h"

@implementation HNDownLoadFile

+ (BOOL)JudgePathIsRealWithFileName:(NSString *)FileName
{
    NSFileManager *File = [NSFileManager defaultManager];
        FileName = [NSString stringWithFormat:@"/%@/%@",Mp3FileUrl,FileName];
        NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:FileName];
        if ([File fileExistsAtPath:path])
        {
            return YES;
        }
        else
        {
            return NO;
        }
}


+ (void)DownFileWithModel:(HNHappyFamilyMusicWorldModel *)Model Progress:(void (^)(CGFloat))Progress Complete:(void(^)(NSString *FullPath,NSError *Err))Complete
{
    NSString *FileName = [NSString stringWithFormat:@"/%@",Mp3FileUrl];
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:FileName];

    
    [XDHttpTool DownLoadFileWithUrlStr:Model.absoluteUrl FileName:[NSString stringWithFormat:@"%@.%@",Model.musicTitle,[Model.absoluteUrl pathExtension]] Path:path Progress:Progress Complete:Complete];
    
 }


+ (void)RemovePathForCheckPath:(NSString *)Path
{
     NSFileManager *File = [NSFileManager defaultManager];

    NSError *Error = nil;
    [File removeItemAtPath:Path error:&Error];

}



+ (NSArray<HNHappyFamilyMusicWorldModel *> *)GetAllDownLoadMusic
{
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:Mp3FileUrl];
    NSFileManager *File = [NSFileManager defaultManager];
    NSArray *Arr = [File subpathsAtPath:path];
    NSMutableArray *MusicArr = [NSMutableArray array];
    for (NSString *UrlStr in Arr)
    {
        HNHappyFamilyMusicWorldModel *Model = [[HNHappyFamilyMusicWorldModel alloc] init];
        NSString *FileName = [UrlStr stringByDeletingPathExtension];
        Model.musicTitle = FileName;
        Model.absoluteUrl = [path stringByAppendingPathComponent:UrlStr];
        [MusicArr addObject:Model];
    }
    return MusicArr;

}
@end
